Skip to content

Fix bounds check in CacheVC::scanObject#13263

Merged
traeak merged 1 commit into
apache:masterfrom
traeak:cache_scan_doc_hlen
Jun 16, 2026
Merged

Fix bounds check in CacheVC::scanObject#13263
traeak merged 1 commit into
apache:masterfrom
traeak:cache_scan_doc_hlen

Conversation

@traeak

@traeak traeak commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Fix bounds check in CacheVC::scanObject, requires on disk corruption.

The prior check compared doc->data() - buf->data() against io.aiocb.aio_nbytes cast to int. The pointer arithmetic could wrap when doc->hlen (read from disk) was very large, and the int cast truncated size_t buffer sizes, so the check could pass while doc->hdr() and the subsequent HTTPInfo::unmarshal walked memory past the I/O buffer.

Re-express the check in the unsigned size_t domain and validate doc->hlen directly against the bytes remaining after the Doc header, guarding each subtraction so it cannot underflow.

Copilot AI review requested due to automatic review settings June 12, 2026 15:30
@traeak traeak self-assigned this Jun 12, 2026
@traeak traeak added the Cache label Jun 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens cache object scanning in CacheVC::scanObject by rewriting a bounds check to avoid signed overflow/truncation and ensuring doc->hdr() / HTTPInfo::unmarshal cannot walk past the end of the AIO read buffer when doc->hlen is corrupt or maliciously large.

Changes:

  • Replace the prior pointer-difference/int-cast bounds check with size_t-domain validation.
  • Add guarded subtractions to ensure Doc header and doc->hlen fit within the bytes remaining in the read buffer before unmarshalling.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@cmcfarlen cmcfarlen added this to the 11.0.0 milestone Jun 15, 2026

@masaori335 masaori335 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you!

@traeak traeak merged commit dd38491 into apache:master Jun 16, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this to For v10.1.1 in ATS v10.1.x Jun 16, 2026
@github-project-automation github-project-automation Bot moved this to For v10.2.0 in ATS v10.2.x Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: For v10.1.1
Status: For v10.2.0

Development

Successfully merging this pull request may close these issues.

4 participants